package com.yuanluludev.app.navigationview

import android.Manifest
import android.view.View
import androidx.fragment.app.Fragment
import com.yuanluludev.app.R
import com.yuanluludev.app.databinding.FragmentBlankOneBinding
import com.yuanluludev.lib_aop.Permissions
import com.yuanluludev.lib_aop.SingleClick
import com.yuanluludev.lib_base.base.BaseVMWithDBFragment
import com.yuanluludev.lib_base.base.BaseViewModel
import com.yuanluludev.lib_utils.util.*
import kotlinx.android.synthetic.main.fragment_blank_one.*
import org.json.JSONObject


/**
 * 此fragment里面不能使用 getActivity()方法  避免报错“not attach a activity”
 */
class BlankOneFragment : BaseVMWithDBFragment<BaseViewModel, FragmentBlankOneBinding>() {

    override fun getLayoutResId() = R.layout.fragment_blank_one

    override fun viewModelClass() = BaseViewModel::class.java


    override fun initEvents() {

//        BarUtils.setStatusBarColor(titleBar, ColorUtils.getColor(R.color.color_666666))
//        BarUtils.addMarginTopEqualStatusBarHeight(titleBar)

//        BarUtils.addMarginTopEqualStatusBarHeight(titleBar)
//       LogUtils.e("${ (mContext as FragmentActivity).supportFragmentManager.toString()}")
//        startPlay(this)
        setOnClickListener(R.id.tvShowDialog)
//        tvShowDialog?.setOnClickListener {
//            CommonDialogUtils.showCenterListWithCheckPop(
//                mContext!!,
//                array = arrayOf("你好", "第二个","第三份"),
//                listener = {pos, _ ->
//                },
//            )

//            mContext?.apply {
//                Pgy.checkVersionUpdate(
//                    (this as Activity),
//                    true,
//                    isBackgroundDownload = true,
//                    showLoading = { showLoading("正在检查更新...") },
//                    hideLoading = { hideLoading() },
//                )
//            }
//            activity?.startActivity(Intent(mContext!!, MainActivity::class.java))
//
//            tvShowDialog?.postDelayed({
//                ThreadUtils.runOnUiThread {
//                    CommonDialogUtils.showConfirmDialog(mContext!!, content = "测试弹窗西安市  天竺")
//                    activity?.finish()
//                }
//            }, 3000)

//            "你好".toastTipMiddle()
//        }

    }

    @SingleClick
    override fun onClick(view: View) {
        when (view.id) {
            R.id.tvShowDialog -> {
                val json = "{\"avgFF75\":0,\"dataTime\":1658246400000,\"talFF75\":0,\"avgFF78\":0,\"talFF78\":0}"
                LogUtils.e(GsonUtils.toJson(JsonUtils.getAllKey(JSONObject(json))))
            }
        }

//        startActivityForResult(SampleActivity::class.java, object :
//            BaseActivity.OnActivityCallback {
//            override fun onActivityResult(resultCode: Int, data: Intent?) {
//                if (resultCode == AppCompatActivity.RESULT_OK) {
//                    data?.getStringExtra("param")?.toastTipMiddle()
//                }
//            }
//        })
//        showLoading(loadingTip = "加载了。额")
//        LogUtils.e("AppLog", "=============== 1 被点击了=============")
    }

    @Permissions(
        value = [Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION],
        isShowGuideDialog = true
    )
    private fun startPlay(fragment: Fragment) {

        LogUtils.e("AppLog", "=============== 进入了 权限方法 =============")

//        VideoPlayActivity.Builder()
//            .setVideoTitle("速度与激情特别行动")
//            .setVideoSource("http://vfx.mtime.cn/Video/2019/06/29/mp4/190629004821240734.mp4")
//            .setActivityOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
//            .start(mContext?:return)

    }

    override fun lazyLoadData() {
    }


}